//
//  CartViewController.m
//  MyFramework
//
//  Created by 余洋 on 2018/5/8.
//  Copyright © 2018年 余洋. All rights reserved.
//

#import "CartViewController.h"
#import "SingleTableViewCell.h"
#import "TabViewController.h"
#import "VerificationCodeViewController.h"
#import "FilePreviewViewController/FilePreviewViewController.h"

@interface CartViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<NSString *> *tableData;

@end

@implementation CartViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - UI
- (void)createTableView {
    [self.tableView registerNib:[UINib nibWithNibName:@"SingleTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SingleTableViewCell"];
    self.tableView.estimatedRowHeight = 21.f;
}

#pragma mark - UItableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SingleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SingleTableViewCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"SingleTableViewCell" owner:self options:nil].lastObject;
    }
    cell.title = self.tableData[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        TabViewController *tabVC = [[TabViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:tabVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    } else if (indexPath.row == 1) {
        VerificationCodeViewController *verificationCodeVC = [[VerificationCodeViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:verificationCodeVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    } else if (indexPath.row == 2) {
        FilePreviewViewController *filePreviewVC = [[FilePreviewViewController alloc] init];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:filePreviewVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
}

#pragma mark - 懒加载
- (NSMutableArray<NSString *>*)tableData {
    if (!_tableData) {
        _tableData = [NSMutableArray arrayWithObjects:@"选项卡Tab bar",@"验证码输入框",@"文件预览", nil];
    }
    return _tableData;
}

@end
